﻿<UserControl x:Class="MindTree.PerfWorkbench.Azure.Monitor.AzureAppTreeViewControl"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:src="clr-namespace:MindTree.PerfWorkbench.Azure.Monitor.AzureMonitor"
             xmlns:commandlib="clr-namespace:MindTree.PerfWorkbench.Azure.Monitor.CommandLib;assembly=AzureCommandLib"
             xmlns:core="clr-namespace:MindTree.PerfWorkbench.Azure.Monitor.Core;assembly=Core"
             mc:Ignorable="d" 
             d:DesignWidth="262">
    
    <Grid Width="249">
        <Grid.Resources>
            <LinearGradientBrush 
                x:Key="TreeViewItemBackground"  
                EndPoint="1,0.5" 
                StartPoint="0,0.5">

                <GradientStop Color="#FFA6CAEC" Offset="0"/>
                <GradientStop Color="#FFAFD0EE" Offset="1"/>
                <GradientStop Color="#FFE4EFF8" Offset="0.498"/>

            </LinearGradientBrush>

            <!-- Application Header Templates -->
            <DataTemplate x:Key="ApplicationHeaderTemplate" DataType="{x:Type core:AzureAppDeployment}">
                <StackPanel Orientation="Horizontal" Width="Auto">
                    <TextBlock Text="{Binding Path=FullName}" />
                </StackPanel>
            </DataTemplate>

            <!-- Role Header Template -->
            <DataTemplate x:Key="RoleHeaderTemplate" DataType="{x:Type core:AzureRole}">
                <StackPanel Orientation="Horizontal" Width="Auto">
                    <TextBlock Text="{Binding RoleName}" />
                </StackPanel>
            </DataTemplate>

            <!-- Role Instance Header Template -->
            <DataTemplate x:Key="RoleInstanceHeaderTemplate" DataType="{x:Type core:AzureRoleInstance}">
                <StackPanel Orientation="Horizontal" Width="Auto">
                    <TextBlock Text="RoleInstance" />
                </StackPanel>
            </DataTemplate>

            <DataTemplate x:Key="RoleInstanceTemplate">
                <Border BorderBrush="AliceBlue" BorderThickness="1" CornerRadius="10"
                        Background="{StaticResource TreeViewItemBackground}" >
                  
                    <Grid Margin="5,5,5,5">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition />
                            <ColumnDefinition />
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition/>
                            <RowDefinition/>
                        </Grid.RowDefinitions>
                        <TextBlock Text="{Binding Path=RoleInstanceId}" 
                                       Grid.Column="0" Grid.Row="0" />
                    </Grid>
                   
                </Border>
            </DataTemplate>

            <!-- Role Content Template-->
            <HierarchicalDataTemplate x:Key="RoleTemplate"
                                       ItemsSource="{Binding Instances}"
                                      ItemTemplate="{StaticResource RoleInstanceTemplate}"    >

                <Border BorderBrush="AliceBlue" BorderThickness="1" CornerRadius="10"
                        Background="{StaticResource TreeViewItemBackground}" >
                   
                    <Grid Margin="5,5,5,5">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition />
                            <ColumnDefinition />
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition/>
                            <RowDefinition/>
                        </Grid.RowDefinitions>
                        <TextBlock Text="{Binding Path=RoleName}" 
                                       Grid.Column="0" Grid.Row="0" />
                    </Grid>
                  
                </Border>
            </HierarchicalDataTemplate>

            <!-- Application Content Template -->
            <HierarchicalDataTemplate x:Key="ApplicationTemplate"
                                      ItemsSource="{Binding Roles}"
                                      ItemTemplate="{StaticResource RoleTemplate}">
                <Border x:Name="ApplicationTemplateBorder" BorderBrush="AliceBlue" 
                        BorderThickness="1" CornerRadius="10"
                        Background="{StaticResource TreeViewItemBackground}" >
                    
                    <Grid Margin="5,5,5,5">
                        <Grid.RowDefinitions>
                            <RowDefinition/>
                            <RowDefinition/>
                        </Grid.RowDefinitions>
                        <TextBlock Grid.Row="0" Text="AzureApplication" />
                    </Grid>
                </Border>
            </HierarchicalDataTemplate>
        </Grid.Resources>
        <TreeView Height="285" 
                              HorizontalAlignment="Left" 
                              Margin="8,7,0,0" 
                              Name="RolesView" 
                              VerticalAlignment="Top" 
                              Width="229"                               
                              ItemsSource="{Binding}" 
                                ItemTemplate="{StaticResource ApplicationTemplate}"
                                TreeViewItem.Expanded="RolesView_Expanded"
                                TreeViewItem.Collapsed="RolesView_Collapsed">

            <TreeView.ItemContainerStyle>
                <!-- This Style binds a TreeViewItem to a TreeViewItemViewModel. -->
                <Style TargetType="{x:Type TreeViewItem}">
                    <Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}" />
                    <Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}" />
                    <Setter Property="FontWeight" Value="Normal" />
                    <Style.Triggers>
                        <Trigger Property="IsSelected" Value="True">
                            <Setter Property="FontWeight" Value="Bold" />
                        </Trigger>
                    </Style.Triggers>
                </Style>
            </TreeView.ItemContainerStyle>

        </TreeView>
    </Grid>
</UserControl>
